<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.content" placeholder="反馈内容" clearable></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" size="medium" v-on:click="handleCurrentChange(1)">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="users" stripe highlight-current-row v-loading="listLoading" border style="width: 100%;">
			<!--<el-table-column prop="id" label="ID" min-width="30" align="center"></el-table-column>-->
			<el-table-column prop="userInfo.nickname" label="昵称" min-width="80" align="center"></el-table-column>
			<el-table-column prop="userInfo.mobile" label="手机号码" min-width="80" align="center"></el-table-column>
			<el-table-column prop="content" label="反馈内容" min-width="80" align="center"></el-table-column>
			<el-table-column prop="img" label="图片" align="center" min-width="80">
                <template slot-scope="scope">
                	<div v-if="scope.row.picUrls.length == 0">/</div>
                	<div v-else v-for="item in scope.row.picUrls">
            	    	<el-popover placement="top-start" title="" trigger="click">
		                  <img :src="item" alt="" style="width: 500px;">
		                  <img slot="reference" :src="item" style="width: 40px;height: 40px;object-fit: cover;">
		                </el-popover>
                	</div>
                </template>
            </el-table-column>
			<!--<el-table-column prop="status" label="状态" min-width="60" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.status == 0" style="color: red;font-weight: bold;">未处理</span>
					<span v-if="scope.row.status == 1" style="color: #00CC00;font-weight: bold;">已处理</span>
				</template>
			</el-table-column>
			<el-table-column prop="result" label="回复内容" min-width="80" align="center">
				<template slot-scope="scope">
					<div class="maxH">{{scope.row.result}}</div>
				</template>
			</el-table-column>
			<el-table-column prop="updateTime" label="处理时间" min-width="110" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.updateTime !== null && scope.row.updateTime !== undefined && scope.row.updateTime !== ''">{{timestampFormat(scope.row.updateTime)}}</span>
					<span v-else>/</span>
				</template>
			</el-table-column>-->
			<el-table-column prop="addTime" label="反馈时间" :formatter="formatDate" min-width="110" align="center" />
			<!--<el-table-column label="操作" min-width="100" align="center">
				<template slot-scope="scope">
					<el-button size="mini" v-if="scope.row.status == 0" @click="handleEdit(scope.$index, scope.row)">未处理</el-button>
					<el-popover v-if="scope.row.status == 1" placement="bottom" title="提示" width="150" trigger="click" content="该反馈已处理，请勿重复提交！">
                        <el-button slot="reference" type="success" plain size="mini">已处理</el-button>
                    </el-popover>
                    <el-button type="danger" size="mini" plain @click="handleDel(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>-->
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="prev, pager, next, jumper" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

		<!--编辑界面-->
		<el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false" width="500px">
			<el-form :model="editForm" label-width="80px" ref="editForm">
				<el-form-item label="回复内容" prop="result" :rules="[{ required: true, message: '请填写内容', trigger: 'blur' }]">
					<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="editForm.result" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="mini" @click.native="editFormVisible = false">取消</el-button>
				<el-button size="mini" type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>
		<!--图片-->
		<el-dialog :visible.sync="photoFormVisible" :close-on-click-modal="false" width="1200px" style="margin-top: -80px;">
			<el-row>
            	<el-carousel :interval="2500" arrow="always">
                    <el-carousel-item v-for="item in this.photoForm.photo.split(',')" :key="item.index">
                        <img :src="item" style="width: 100%;height: 100%;"/>
                    </el-carousel-item>
                </el-carousel>
           </el-row>
		</el-dialog>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	
	export default {
		data() {
			return {
				filters: {
					content: '',
				},
				users: [],
				total: 0,
				page: 1,
				pageSize: 10,
				listLoading: false,
				editFormVisible: false,
				editLoading: false,
				
				editForm: {
					id: '',
					status:1,
					result: ''
				},
				photoFormVisible: false,
				photoForm:{
					photo:''
				},
			}
		},
		methods: {
			//状态
			status: function (row, column) {
				return row.status === 0 ? '未处理' :row.status === 1 ? '已处理' : '其他';
			},
			//时间转换开始时间 
			formatDate(row, column) {
                let date = new Date(parseInt(row.addTime));
                let Y = date.getFullYear() + '-';
                let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
                let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
                let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
                let m = date.getMinutes()  < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
                let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                return Y + M + D + h + m + s;
            },
            zeroize(num) {
                return (String(num).length == 1 ? "0" : "") + num;
            },
            timestampFormat(timestamp) {
                var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
                var timestampDiff = curTimestamp - parseInt(timestamp / 1000); // 参数时间戳与当前时间戳相差秒数
                var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
                var tmDate = new Date(parseInt(timestamp / 1000) * 1000); // 参数时间戳转换成的日期对象
                var Y = tmDate.getFullYear(),
                m = tmDate.getMonth() + 1,
                d = tmDate.getDate();
                var H = tmDate.getHours(),
                i = tmDate.getMinutes(),
                s = tmDate.getSeconds();
                return (Y + "-" + this.zeroize(m) + "-" + this.zeroize(d) + " " + this.zeroize(H) + ":" + this.zeroize(i) + ":" + this.zeroize(s));
            },
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取列表
			getUsers:function (){
				this.listLoading = true;
				let para = {
					page: this.page,
					size: this.pageSize,
					content: this.filters.content,
				};
				var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','admin_five_palace_token':JSON.parse(sessionStorage.getItem('token'))},
				});  
				instance.post('admin/platform/manage/feedbackList', this.qs.stringify(para)).then(data => {
					
					let  res = data.data;
					if (res.code !== 0) {
						this.$message({
							message: res.msg,
							type: 'error'
						});
					} else {
						this.total = res.total;
						this.users = res.rows;
						this.listLoading = false;
					}
				});
			},
			//显示图片页面
			handlePhoto: function (index, row) {
				this.photoFormVisible = true;
				console.log(row);
				this.photoForm.photo = row.picture;
			},
			
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm.id = row.id;
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							let para = {
								id:this.editForm.id,
								status:1,
								result:this.editForm.result,
							}
							this.$http.post('admin/feedback/update', this.qs.stringify(para)).then(data => {
								
								let  res = data.data;
								if (res.code !== 200) {
									this.$message({
										message: res.msg,
										type: 'error'
									});
								} else {
									this.editLoading = false;
									this.$message({
										message: '提交成功',
										type: 'success'
									});
									this.$refs['editForm'].resetFields();
									this.editFormVisible = false;
									this.getUsers();
								}
							});
						});
					}
				});
			},
			//删除
			handleDel(id) {
				this.$confirm('确认删除吗?', '提示', {}).then(() => {
					this.listLoading = true;
					this.$http.post('admin/feedback/del', this.qs.stringify({feedbackId: id})).then(data => {
						
						let  res = data.data;
						if (res.code !== 200) {
							this.$message({
								message: res.msg,
								type: 'error'
							});
						} else {
							this.$message({
								message: '成功',
								type: 'success'
							});
							this.getUsers();
						}
					})
				}).catch(() => {

				});
			},
		},
		mounted() {
			this.getUsers();
		}
	}

</script>

<style scoped>

</style>